import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { PSAjaxControlContainerImpl } from '../psajax-control-container-impl';
import { IPSExpBar } from './ipsexp-bar';
import { IPSLanguageRes } from '../../res/ipslanguage-res';
import { IPSSysImage } from '../../res/ipssys-image';

export class PSExpBarImpl extends PSAjaxControlContainerImpl implements IPSExpBar {
  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定标题图标');
    }
    return value;
  }

  get title(): string {
    return this.M.title;
  }

  protected titlepslanguageres: IPSLanguageRes | null = null;

  getTitlePSLanguageRes(): IPSLanguageRes | null {
    if (this.titlepslanguageres != null) return this.titlepslanguageres;
    const value = this.M.getTitlePSLanguageRes;
    if (value == null) {
      return null;
    }
    this.titlepslanguageres = this.getPSModel4('res.IPSLanguageRes', value, 'getTitlePSLanguageRes') as IPSLanguageRes;
    return this.titlepslanguageres;
  }

  get titlePSLanguageRes(): IPSLanguageRes | null {
    return this.getTitlePSLanguageRes();
  }

  getTitlePSLanguageResMust(): IPSLanguageRes {
    const value = this.getTitlePSLanguageRes();
    if (value == null) {
      throw new Error('未指定抬头语言资源对象');
    }
    return value;
  }

  get xDataControlName(): string {
    return this.M.xDataControlName;
  }

  get enableCounter(): boolean {
    return this.M.enableCounter;
  }

  get enableSearch(): boolean {
    return this.M.enableSearch;
  }

  get showTitleBar(): boolean {
    return this.M.showTitleBar;
  }

  get cls(): string {
    return 'PSExpBarImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.expbar.IPSExpBar') return true;
    return super.instanceof(cls);
  }
}
